<?php

namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Contracts\Validation\Validator;
use Illuminate\Http\Exceptions\HttpResponseException;

class AddTags extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'title' => 'required|max:100',
            'ColumnID' => 'required|integer|min:1',
        ];
    }

    public function messages(){
        return [
            'title.required' => '标题不能为空！',
            'ColumnID.required' => '专栏id不能为空！',
            'ColumnID.integer' => '专栏id为整形！',
            'ColumnID.min' => '专栏id大于0'

        ];
    }

    protected function failedValidation(Validator $validator)
    {
        throw (new HttpResponseException(response()->json([
            'code'=>100,
            'messages' => $validator->errors()->all(),
        ],422)));
    }

}
